home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Development Kits / MPW etc / Miscellaneous / ThreeWayMerge / ThreeWayMergeBranch < prev   
Encoding:
Text File  |  1996-02-26  |  4.9 KB  |  180 lines  |  [TEXT/MPS ]

  1. #
  2. #    File:        ThreeWayMergeBranch
  3. #
  4. #    Contains:    xxx put contents here xxx
  5. #
  6. #    ThreeWayMergeBranch - Merges any changes you have locally with the current
  7. #        latest version on your Named Branch (or main branch if you don't have one).
  8. #        The resulting merge is placed into a modified readonly file that is derived
  9. #        from the latest version.
  10. #
  11. #        You can use this to merge in changes from other branches by checking them
  12. #        out and then doing a merge.
  13. #
  14. #    Usage:    ThreeWayMergeBranch file
  15. #
  16. #    ThreeWayMergeBranch is a variation on the traditional MergeBranch.
  17. #    It renames the branch revision "file" to "file",branch and
  18. #    checks out the latest revision on the revision trunk modified read only.
  19. #
  20. #    It also checks out the version of the file from which your
  21. #    local was derived (either checked out for modify or modified read only).
  22. #    This file is called the base.  Your version is version1, while the
  23. #    current main branch is version2.  We then call ThreeWayMergeBranch
  24. #    to merge the changes automatically. The result is that you are up-to-date
  25. #    with the main branch, and can check in after you have verified that
  26. #    the merge was successful.  Note that ThreeWayMergeBranch marks
  27. #    conflicts with lines containing •••.
  28. #
  29. #    To add MergeBranch to a menu, execute the following command:
  30. #
  31. #        AddMenu Project 'ThreeWayMergeBranch' ∂
  32. #            'ThreeWayMergeBranch "{Active}" ∑∑ "{WorkSheet}"'
  33. #
  34. #    This script creates many temporary files, in the {temporary} folder,
  35. #    which are deleted on exit or abort. It leaves your original file and
  36. #    the base.
  37. #
  38. #    ThreeWayMergeBranch calls the script ThreeWayMerge.
  39. #
  40. #    Owned by:    Jens Alfke
  41. #
  42. #    Copyright:    © 1988 - 1990, 1995-1996 by Apple Computer, Inc., all rights reserved.
  43. #
  44. #    Change History (most recent first):
  45. #
  46. #         <1>     5/25/95    jpa        first checked in
  47. #
  48. #    To Do:
  49. #
  50.  
  51.  
  52. Set Exit 1
  53. Begin
  54.     
  55.     #    Check parameters.
  56.     
  57.     If {#} ≠ 1
  58.         Echo "### Usage - {0} file"
  59.         Exit 0
  60.     End
  61.     
  62.     #    Make sure the file exists
  63.  
  64.     If "" == "`Exists -f "{1}"`"
  65.         Echo "### {0} - File ∂"{1}∂" not found"
  66.         Exit 4
  67.     End
  68.         
  69.     #    Break apart the pathname.
  70.     
  71.     Set f "{1}"
  72.     If "{f}" =~ /(≈)®1:([¬:]+)®2/
  73.         Set dir "{®1}:"
  74.         Set f "{®2}"
  75.     Else
  76.         Set dir `directory`
  77.     End
  78.  
  79.     Set path "{dir}{f}"
  80.  
  81.     #    Get project information on the file.
  82.     Set info1 "`projectinfo "{path}"`"
  83.  
  84.     If "{info1}" =~ /[∂']*(≈)®1,([¬ ∂']+)®2[∂']* ≈Project: (≈∫)®3≈    Task: (≈)®4/
  85.         Set file "{®1}"
  86.         Set rev "{®2}"
  87.         Set proj "{®3}"
  88.         Set task "{®4}"
  89.         Set comment "Merged from branch {rev}."
  90.     End
  91.     
  92.     
  93.     #    If the file is checked out for modification, check it in
  94.     #     and call projectinfo again to get the branch's new revision number.
  95.     
  96.     If "{rev}" =~ /≈∂+/
  97.         CheckIn -y "{path}" ≥dev:null                
  98.         Set info1 "``projectinfo "{path}"``"
  99.         If "{info1}" =~ /[∂']*(≈)®1,([¬ ∂']+)®2[∂']* ≈Project: (≈∫)®3≈/
  100.             Set file "{®1}"
  101.             Set rev "{®2}"
  102.             Set proj "{®3}"
  103.         End
  104.     End
  105.     
  106.     # build an argument indicating our current Branch Name    
  107.     set NameSpec ""
  108.     if "{gMyBranchName}" ≠ ""
  109.         set NameSpec "-n ∂"{gMyBranchName}∂""
  110.     End
  111.     
  112.     #    Get projectinfo on the file's latest revision for the NameBranch you are workin on
  113.     
  114.     Set info2 "`projectinfo {nameSpec} -s -project "{proj}" "{f}" ≥ dev:null`"
  115.     If "{info2}" == ""
  116.         Alert "Project ∂"{proj}∂" is not mounted."        
  117.         Exit 4
  118.     End
  119.     
  120.     If "{info2}" =~ /∂'[¬,]+,([¬ ∂']+)®2∂'≈/
  121.         Set latestRev "{®2}"
  122.     Else If "{info2}" =~ /[¬,]+,([¬ ]+)®2 ≈/
  123.         Set latestRev "{®2}"
  124.     Else
  125.         Alert "Latest rev of File ∂"{f}∂" is checked out for modification.  Cannot merge at this time."        
  126.         Exit 4
  127.     End
  128.     
  129.     Set OldExit Exit
  130.     Set Exit 0
  131.         Close "{path}" ≥≥ dev:null
  132.     Set Exit {OldExit}
  133.  
  134.     # figure out what version we branched from
  135.     set revBase "`FindCommonBaseRevision "{rev}" "{latestRev}"`"
  136.  
  137.     if "{revBase}" == "{rev}"
  138.         Echo "### For file ∂"{file}∂", latest {latestRev} is derived from your {rev}"
  139.         # checkout current latest version
  140.         CheckOut "{path},{latestRev}" -project "{proj}"
  141.         Else
  142.         #    Rename the branch revision and checkout the trunk revision for modification.
  143.     
  144.         Set branchf "{path},{rev}"
  145.         Duplicate -y "{path}"  "{TempFolder}{file}"
  146.         Rename -y "{path}" "{branchf}"
  147.         
  148.         # go and get the original version that we branched off of
  149.         Set branchBase "{path},{revBase}"
  150.         CheckOut "{branchBase}" -project "{proj}"
  151.         Rename -y "{path}" "{branchBase}"
  152.     
  153.         # checkout current latest version
  154.         CheckOut "{path},{latestRev}" -project "{proj}"
  155.     
  156.         # lets just see if there is nothing to do first...
  157.         Set Exit 0
  158.         Equal -q "{branchf}" "{path}"
  159.         Set MyStatus {Status}
  160.         Set Exit 1
  161.     
  162.         If {MyStatus} == 0
  163.             Echo "### For file ∂"{path}∂", {rev} and {latestRev} are equal"
  164.         Else
  165.             Echo "### For file ∂"{path}∂", your {rev} merged with {latestRev} based on {revBase}"
  166.         
  167.             # use my nifty new script
  168.             ThreeWayMerge "{branchBase}" "{branchf}" "{path}" > "{path}"•Merge
  169.             Set MyStatus {Status}
  170.         
  171.             ModifyReadOnlyBranch "{path}"
  172.             Catenate "{path}"•Merge > "{path}" 
  173.             Delete "{path}"•Merge
  174.         End
  175.         Delete "{branchf}"        # original file
  176.         Delete "{branchBase}"    # base on which the comparison was made
  177.     End
  178. End
  179.  
  180.